$ErrorActionPreference = "Stop"
$ExitCode = 1

# Make sure the nuget executable is writable
Set-ItemProperty NuGet.exe -Name IsReadOnly -Value $false

# Make sure the nupkg files are writeable and delete old ones
if (Test-Path *.nupkg) {
    Set-ItemProperty *.nupkg -Name IsReadOnly -Value $false

#    Get-ChildItem *.nupkg | ForEach-Object { 
#        Remove-Item $_.Name
#    }
}

Invoke-Command {.\NuGet.exe update -Self -Verbosity Quiet -NonInteractive} -ErrorAction Stop

# Create package
Invoke-Command {.\NuGet.exe pack Lib.Web.Mvc.nuspec -Verbosity Quiet -NonInteractive}
$ExitCode = 0

Exit $ExitCode